#include<iostream>
using ll = long long;
using namespace std;
int n;
const int N = 1e5 + 10;
ll a[N];
int x;
int main()
{
    cin >> n >> x;
    for (int i = 1; i <= n; i++) cin >> a[i];
    // 这都啊题目就是简单的谈心，所以直接按照样例进行模拟就好了
    ll sum = 0;
    for (int i = 1; i <= n; i++)
    {
        if (a[i - 1] + a[i] > x)
        {
            ll d = a[i - 1] + a[i] - x;
            sum += d;
            a[i] -= d;
        }
    }

    cout << sum << endl;
    return 0;
}